Using the Central Accordion Tab Component
Table of Contents
Adding Tabs to the Accordion Tab Component
The Accordion Tab API contains three methods for adding data and tabs to the component:
MAccordionTab.addItemMAccordionTab.addItemAtMAccordionTab.setDataProvider
As you have probably figured out by looking at the method above, the component supports the DataProvider API.
Each tab can have a label (which is required) and optional data associated with it. Adding a tab to the component is as simple as calling addItem, and passing a label to the method.
Adding a Tab Using addItem
The easiest way to add a tab to the component is to use the addItem method,
which appends a tab with the specified label to the component.
Note that in order to test the component, you will have to install and run the test application within Central. I will not cover the steps on how to do that here. If you are not sure how to install an application into Central, please read the article Getting Started with Macromedia Central. You can use the test file created in that article for the examples in this article. This article assumes that you are testing your application within Central.
Adding a single tab is as easy as dragging the Accordion Tab component
into your application, giving it an instance name ("myTab")
and adding the following ActionScript code:
function onActivate()
{
myTab.addItem("Tab 1");
}
Central.initApplication(this, this);
However, if you test your movie, you will not see any tabs but a bevel background with a title “Tab 1” (see Figure 2).

Figure 2. What you see when testing your movie
This is because if you add only one item to the component instance, it does not appear as a colored tab but as a title in the content area. You need a minimum of two items to have differentiated tabs visible to the user.
You can add multiple tabs by calling addItem multiple
times.
function onActivate()
{
myTab.additem("Tab 1");
myTab.additem("Tab 2");
myTab.additem("Tab 3");
}
Central.initApplication(this, this);
This creates a tab control with three tabs (see Figure 3).

Figure 3. A tab control with three tabs
If you look at the SDK documentation for the addItem method,
you will notice that it can take two parameters. The second parameter
is data that will be associated with the tab. This data can be any
ActionScript data type including an object, array, string, or even
a reference to a movie clip. This last item will be useful if you want
to show how to change application views based on the user’s interaction
with the tabs.
Adding a Tab Using setDataProvider
Since the Tab component supports the DataProvider API, you can also
use a Central.DataProviderClass to populate the tab and
its data. The component recognizes the following data provider items
and properties:
- label specifies the label of the tab.
- data specifies the data associated with the tab.
- icon enables you to add a favorites icon to the tab.
As is the case with the addItem method, only the label
property is required; the other properties are optional. The following
snippet shows how to use setDataProvider to add three tabs to the component:
function onActivate()
{
var dp = new Central.DataProviderClass();
dp.addItem({label:”Tab 1”});
dp.addItem({label:”Tab 2”});
dp.addItem({label:”Tab 3”});
myTab.setDataProvider(dp);
}
Central.initApplication(this, this);
The result resembles the tab control created using the addItem method
(see Figure 3).